﻿using System;
using System.Linq;

namespace unTroublemaker.Conditions
{
    public class EnvVariableExistsCondition : SpecificationItemBase
    {
        private readonly string _name;

        public EnvVariableExistsCondition(string name)
        {
            _name = name;
        }

        protected override bool RunTest()
        {
            return Environment.GetEnvironmentVariables()
                       .Keys.Cast<object>()
                       .Any(key => key.ToString().Equals(_name, StringComparison.CurrentCultureIgnoreCase));
        }

        public override string DisplayName
        {
            get { return "Check existance of environment variable named " + _name; }
        }
    }
}
